package demo03_迭代;

import cn.hutool.core.io.FileUtil;

import java.io.File;
import java.io.IOException;

public class Test3 {
    public static void searchFile(File dir,String fileName) throws IOException {
        if (dir==null||!dir.exists()||!dir.isDirectory()){
            return;
        }

        File[] files = dir.listFiles();
        if (files!=null){
            for (File file : files)
                if (file.isFile()){
                    System.out.println("判断文件"+file.getName());
                    if (file.getName().equals(fileName)){
                        System.out.println("找到文件："+file.getAbsolutePath());
                        Runtime runtime = Runtime.getRuntime();
                        runtime.exec("notepad"+file.getAbsolutePath());
                        System.out.println(file);
                    }
                }else {
                    System.out.println("判断文件夹"+file.getName());
                    searchFile(file,fileName);
                }
        }
    }
    public static void main(String[] args) throws IOException {
        searchFile(new File("H:\\"),"无职13.epub");
    }
}
